﻿
//弹窗
function showModal(url, selectedTypeModal, title, dialogWidth) {

    if (selectedTypeModal == null || selectedTypeModal == "undefined" || selectedTypeModal == "") {
        //动态指定弹框页面是单选or多选
        selectedType = '单选';
    } else {
        selectedType = selectedTypeModal;
    }
    if (dialogWidth == null || dialogWidth == "undefined" || dialogWidth == "") {
        dialogWidth = '88%';
    }
    if (title == null || title == "undefined") {

        title = '';
    }

    // 弹窗内容部分
    layer.open({
        type: 2, //如果content取的的路径，或者某个页面，type类型应该为2
        title: title,
        area: [dialogWidth, '88%'],
        content: url,

    });

}
//删除提示
function deletealert(data) {
    if (data) {
        if (data.Succeeded && data.Data != null) {


            if (data.Data.code == 200) {
                layer.alert(data.Data.msg, "成功");

                setTimeout(function () {
                    layer.close(layer.index); //自动关闭
                }, 2000);

                return true;
            }
            else {
                layer.alert(data.Data.msg, "失败");
            }

        } else {
            layer.alert(data.Errors);
        }
    } else {
        layer.alert("网络有问题");
    }
    return false;
}
//处理创建和修改成功
function createalert(data, href) {
    if (data) {
        if (data.Succeeded && data.Data != null) {


            if (data.Data.code == 200) {
                layer.alert(data.Data.msg, "成功");
                setTimeout(function () {
                    return window.location.href = href;
                }, 2000);
                return true;
            }
            else {
                layer.alert(data.Data.msg, "失败");
            }

        } else {
            layer.alert(data.Errors);
        }
    } else {
        layer.alert("网络有问题");
    }
    return false;
}
//只有post和get没有漏洞，其他都不安全
function ajaxPost(url, parm) {
    var result;
    var ctoken = getCookie('Token');
    if (ctoken != null) {
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            contentType: 'application/json',
            headers: { 'Authorization': 'Bearer ' + ctoken },
            data: JSON.stringify(parm),
            async: false,
            success: function (data) {
                if (data.StatusCode == 401) {
                    alert('已过期，请重新登录');
                    return window.location.href = '/';//没授权
                }
                result = data;
            }
        });
    }
    else {
        $.ajax({
            url: url,
            type: 'post',
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify(parm),
            async: false,
            success: function (data) {
                result = data;
            }
        });
    }
    return result;
}

function ajaxGet(url) {
    var result;
    $.ajax({
        url: url,
        type: 'get',
        dataType: 'json',
        contentType: 'application/json',
        async: false,
        success: function (data) {
            result = data;
        }
    });
    return result;
} 